from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-12-02 14:02:41.622500
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 02, Dec, 2022
Time: 14:02:48
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.1128
Nobs: 858.000 HQIC: -51.4206
Log likelihood: 11274.3 FPE: 3.84929e-23
AIC: -51.6116 Det(Omega_mle): 3.46808e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299861 0.050124 5.982 0.000
L1.Burgenland 0.110346 0.034447 3.203 0.001
L1.Kärnten -0.104075 0.018357 -5.669 0.000
L1.Niederösterreich 0.210023 0.072033 2.916 0.004
L1.Oberösterreich 0.100437 0.068372 1.469 0.142
L1.Salzburg 0.249062 0.036326 6.856 0.000
L1.Steiermark 0.037347 0.047878 0.780 0.435
L1.Tirol 0.107922 0.038826 2.780 0.005
L1.Vorarlberg -0.060412 0.033480 -1.804 0.071
L1.Wien 0.053740 0.061130 0.879 0.379
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.067938 0.103320 0.658 0.511
L1.Burgenland -0.030097 0.071006 -0.424 0.672
L1.Kärnten 0.049873 0.037840 1.318 0.188
L1.Niederösterreich -0.172808 0.148482 -1.164 0.244
L1.Oberösterreich 0.374503 0.140934 2.657 0.008
L1.Salzburg 0.290145 0.074878 3.875 0.000
L1.Steiermark 0.107689 0.098691 1.091 0.275
L1.Tirol 0.317224 0.080033 3.964 0.000
L1.Vorarlberg 0.022617 0.069013 0.328 0.743
L1.Wien -0.020709 0.126006 -0.164 0.869
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.198002 0.025946 7.631 0.000
L1.Burgenland 0.092785 0.017831 5.204 0.000
L1.Kärnten -0.008354 0.009502 -0.879 0.379
L1.Niederösterreich 0.268103 0.037286 7.190 0.000
L1.Oberösterreich 0.114836 0.035391 3.245 0.001
L1.Salzburg 0.052660 0.018803 2.801 0.005
L1.Steiermark 0.016855 0.024783 0.680 0.496
L1.Tirol 0.098850 0.020098 4.919 0.000
L1.Vorarlberg 0.055933 0.017330 3.227 0.001
L1.Wien 0.111368 0.031642 3.520 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105406 0.026618 3.960 0.000
L1.Burgenland 0.047492 0.018293 2.596 0.009
L1.Kärnten -0.016405 0.009748 -1.683 0.092
L1.Niederösterreich 0.196761 0.038252 5.144 0.000
L1.Oberösterreich 0.279933 0.036308 7.710 0.000
L1.Salzburg 0.119884 0.019290 6.215 0.000
L1.Steiermark 0.100945 0.025425 3.970 0.000
L1.Tirol 0.124111 0.020618 6.019 0.000
L1.Vorarlberg 0.068647 0.017779 3.861 0.000
L1.Wien -0.027622 0.032462 -0.851 0.395
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.129730 0.048309 2.685 0.007
L1.Burgenland -0.051046 0.033200 -1.538 0.124
L1.Kärnten -0.036593 0.017693 -2.068 0.039
L1.Niederösterreich 0.171128 0.069425 2.465 0.014
L1.Oberösterreich 0.133209 0.065896 2.022 0.043
L1.Salzburg 0.288518 0.035011 8.241 0.000
L1.Steiermark 0.033993 0.046145 0.737 0.461
L1.Tirol 0.160374 0.037421 4.286 0.000
L1.Vorarlberg 0.106955 0.032268 3.315 0.001
L1.Wien 0.065390 0.058916 1.110 0.267
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058844 0.038163 1.542 0.123
L1.Burgenland 0.042719 0.026227 1.629 0.103
L1.Kärnten 0.050345 0.013977 3.602 0.000
L1.Niederösterreich 0.227501 0.054844 4.148 0.000
L1.Oberösterreich 0.271867 0.052056 5.223 0.000
L1.Salzburg 0.058587 0.027657 2.118 0.034
L1.Steiermark -0.007608 0.036453 -0.209 0.835
L1.Tirol 0.156647 0.029561 5.299 0.000
L1.Vorarlberg 0.068331 0.025491 2.681 0.007
L1.Wien 0.073401 0.046542 1.577 0.115
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185178 0.045660 4.056 0.000
L1.Burgenland -0.004252 0.031379 -0.136 0.892
L1.Kärnten -0.060623 0.016722 -3.625 0.000
L1.Niederösterreich -0.087735 0.065618 -1.337 0.181
L1.Oberösterreich 0.191428 0.062282 3.074 0.002
L1.Salzburg 0.059344 0.033091 1.793 0.073
L1.Steiermark 0.225859 0.043614 5.179 0.000
L1.Tirol 0.495366 0.035369 14.006 0.000
L1.Vorarlberg 0.047742 0.030499 1.565 0.117
L1.Wien -0.050242 0.055685 -0.902 0.367
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.159160 0.052017 3.060 0.002
L1.Burgenland -0.008347 0.035748 -0.233 0.815
L1.Kärnten 0.066537 0.019051 3.493 0.000
L1.Niederösterreich 0.202072 0.074754 2.703 0.007
L1.Oberösterreich -0.067769 0.070954 -0.955 0.340
L1.Salzburg 0.221806 0.037698 5.884 0.000
L1.Steiermark 0.113776 0.049686 2.290 0.022
L1.Tirol 0.084405 0.040293 2.095 0.036
L1.Vorarlberg 0.121638 0.034745 3.501 0.000
L1.Wien 0.108540 0.063438 1.711 0.087
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357145 0.030712 11.629 0.000
L1.Burgenland 0.009259 0.021107 0.439 0.661
L1.Kärnten -0.024362 0.011248 -2.166 0.030
L1.Niederösterreich 0.227462 0.044137 5.154 0.000
L1.Oberösterreich 0.157121 0.041893 3.751 0.000
L1.Salzburg 0.052283 0.022258 2.349 0.019
L1.Steiermark -0.017142 0.029336 -0.584 0.559
L1.Tirol 0.117769 0.023790 4.950 0.000
L1.Vorarlberg 0.072012 0.020514 3.510 0.000
L1.Wien 0.049870 0.037456 1.331 0.183
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.043360 0.161018 0.191615 0.162878 0.131733 0.124818 0.070213 0.231193
Kärnten 0.043360 1.000000 0.001769 0.131508 0.025445 0.098668 0.427380 -0.051142 0.101703
Niederösterreich 0.161018 0.001769 1.000000 0.344217 0.167802 0.310512 0.127853 0.192326 0.341564
Oberösterreich 0.191615 0.131508 0.344217 1.000000 0.231659 0.339715 0.177075 0.178949 0.274287
Salzburg 0.162878 0.025445 0.167802 0.231659 1.000000 0.151138 0.135680 0.153625 0.140802
Steiermark 0.131733 0.098668 0.310512 0.339715 0.151138 1.000000 0.162923 0.147651 0.092772
Tirol 0.124818 0.427380 0.127853 0.177075 0.135680 0.162923 1.000000 0.122574 0.163995
Vorarlberg 0.070213 -0.051142 0.192326 0.178949 0.153625 0.147651 0.122574 1.000000 0.020286
Wien 0.231193 0.101703 0.341564 0.274287 0.140802 0.092772 0.163995 0.020286 1.000000